package com.ccx.coachsite.ui.customview;


import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.ccx.coachsite.R;


/**
 * 自定义搜索框
 * @author cfb
 *
 */

public class CustomSearchKeyEditView extends LinearLayout implements
		SearchEditInterface {

	Button clearImgBtn;
	EditText keyword;

	public CustomSearchKeyEditView(Context context) {
		super(context);
	}

	public CustomSearchKeyEditView(Context context, AttributeSet attrs) {
		super(context, attrs);

		LayoutInflater.from(context).inflate(R.layout.soft_mgr_soft_search_custom_editview_ccx, this,true); 
		initView();
	}

	private void initView() {
		
		keyword = (EditText) findViewById(R.id.keyword); 
		//keyword.addTextChangedListener(editTextWatcher);
		
		/*
		clearImgBtn = (Button) findViewById(R.id.clearImgBtn); 
		clearImgBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				hideBtn();
				keyword.setText("");
			}
		});
		*/
	}

	TextWatcher editTextWatcher = new TextWatcher() {

		@Override
		public void onTextChanged(CharSequence s, int start, int before, int count) {
		}

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count, int after) {
		}

		@Override
		public void afterTextChanged(Editable s) {
			if (s.length() == 0) {
				hideBtn();
			} else {
				showBtn();
			}
		}
	};

	@Override
	public void hideBtn() {
		
		if ( clearImgBtn.isShown() ) {
			clearImgBtn.setVisibility(View.GONE);
		}
	}

	@Override
	public void showBtn() {
		
		if ( !clearImgBtn.isShown() ) {
			clearImgBtn.setVisibility(View.VISIBLE);
		}
	}
}

interface SearchEditInterface {

	public void hideBtn();

	public void showBtn();
}